$package('YiYa.sysMenu');

YiYa.sysMenu = function(){
	var _box = null;
	var _this = {
		config:{
			event:{
				edit:function(){
					var selected = _box.utils.getCheckedRows();
					if ( _box.utils.checkSelectOne(selected)){
						var record = selected[0];
						_box.handler.edit();
						var url = '../product/loadProdList.do?type=1';
						$.get(url,function(data){
							$('#cc2').combogrid('grid').datagrid('loadData',data);
				        });
						$('#cc5').combobox('setValue',record.merchant.type);
					}
				},
				view:function(){
					var selected = _box.utils.getCheckedRows();
					if ( _box.utils.checkSelectOne(selected)){
						var record = selected[0];
						_box.handler.view();
						var url = '../product/loadProdListByMerchant.do?merchantId='+record.merchant.id;
						$.get(url,function(data){
							$('#cc4').combogrid('grid').datagrid('loadData',data);
				        });
						$('#cc6').combobox('setValue',record.merchant.type);
					}
				}
			},
  			dataGrid:{
  				title:'订单列表',
	   			url:'dataList.do',
	   			columns:[[
					{field:'id',checkbox:true},
					{field:'number',title:'订单编号',width:120,sortable:true},
					{field:'merchant_name',title:'客户',width:80,
			        	  formatter:function(value,row,index){
			        		  return new Object(row["merchant"]).name;
					}},
					{field:'productCode',title:'产品编号',width:120},
					{field:'productName',title:'产品名称',width:120},
				    {field:'productColor',title:'产品颜色',width:80},
				    {field:'productStandard',title:'产品规格',width:80},
					{field:'model',title:'型体',width:120,sortable:true},
					{field:'quantity',title:'数量',width:80,sortable:true},
					{field:'price',title:'单价',width:80,sortable:true},
					{field:'amount',title:'总额',width:80,sortable:true},
					{field:'deadline',title:'交货日期',width:80,sortable:true,
			        	  formatter:function(value,row,index){
			        		  return new Date(row["deadline"]).format("yyyy-MM-dd");
					}},
					{field:'linkman',title:'联系人',width:80,sortable:true},
					{field:'state',title:'订单状态',width:60,sortable:true,
			        	  formatter:function(value,row,index){
				        		if(value == 0){
				        			return "未交货";
				        		}
				        		if(value == 1){
				        			return "已交货";
				        		}
				        	}  
			        },
					{field:'o.create_time',title:'创建时间',width:120,sortable:true,
			        	  formatter:function(value,row,index){
			        		  return row["createTime"];
					  }},
					  {field:'o.update_time',title:'更新时间',width:120,sortable:true,
			        	  formatter:function(value,row,index){
			        		  return row["updateTime"];
					  }},
					  {field:'remark',title:'备注',width:120,
						  formatter:function(value,row,index){
							  if(value!=undefined){
								  if(value.length>10){
									  var str = value.substring(0,8);
									  return str.concat('......');	  
								  }
								  return value;
							  }
					  }}
				]],
				toolbar:[
					{id:'btnadd',text:'添加',btnType:'add'},
					{id:'btnedit',text:'编辑',btnType:'edit'},
					{id:'btndelete',text:'删除',btnType:'remove'},
					{id:'btnview',text:'查看',btnType:'view'}
				]
			}
		},
		init:function(){
			$('.easyui-datebox').datebox({
			    formatter: function(date){ 
			    	return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
			    },
			    parser: function(date){ 
			    	return new Date(Date.parse(date.replace(/-/g,"/")));
			    }
			});
			$('#cc5').combobox({
				onChange:function(newValue,oldValue){
					var url = '../merchant/loadMerchantList.do?type='+newValue;
					$('#cc1').combobox('reload',url);
					$('#cc1').combobox('clear');
					
			    }
			});
			/*
			$('#cc1').combobox({
			    onChange:function(newValue,oldValue){
			    	$("#cc2").combogrid('clear');
			    }
			});
			*/
			$('#cc6').combobox({
				onChange:function(newValue,oldValue){
					var url = '../merchant/loadMerchantList.do?type='+newValue;
					$('#cc3').combobox('reload',url);
					$('#cc3').combobox('clear');
			    }
			});
			_box = new YDataGrid(_this.config); 
			_box.init();
		}
	}
	return _this;
}();

$(function(){
	YiYa.sysMenu.init();
});		